package com.bee.shepherd.web.vo;

import com.google.common.collect.Maps;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;


public class ResultData implements Serializable {

    private static final long serialVersionUID = -2557899737321175514L;

    private boolean ret;
    private Integer status;
    private String message;
    private Date currentTime = new Date();
    private Map<String, Object> data = Maps.newHashMap();

    public static ResultData builderSuccess() {
        ResultData resultData = new ResultData();
        resultData.setStatus(ResultStatus.SUCCESS);
        resultData.setRet(Boolean.TRUE);
        return resultData;
    }

    public static ResultData builderSuccess(Map<String, Object> data) {
        ResultData resultData = new ResultData();
        resultData.setRet(Boolean.TRUE);
        resultData.setStatus(ResultStatus.SUCCESS);
        resultData.setData(data);
        return resultData;
    }

    public static ResultData builderFailure() {
        ResultData resultData = new ResultData();
        resultData.setRet(Boolean.FALSE);
        resultData.setStatus(ResultStatus.SYSTEM_EXCEPTION);
        resultData.setMessage("系统异常");
        return resultData;
    }

    public static ResultData builderFailure(int status, String message) {
        ResultData resultData = new ResultData();
        resultData.setRet(Boolean.FALSE);
        resultData.setStatus(status);
        resultData.setMessage(message);
        return resultData;
    }

    public static ResultData buildSystemFailure(String message) {
        ResultData resultData = new ResultData();
        resultData.setRet(Boolean.FALSE);
        resultData.setStatus(ResultStatus.SYSTEM_EXCEPTION);
        resultData.setMessage(message);
        return resultData;
    }

    public static ResultData buildBusinessFailure(String message) {
        ResultData resultData = new ResultData();
        resultData.setRet(Boolean.FALSE);
        resultData.setStatus(ResultStatus.SERVICE_EXCEPTION);
        resultData.setMessage(message);
        return resultData;
    }

    public ResultData putItem(String key, Object value) {
        this.getData().put(key, value);
        return this;
    }

    public ResultData putAll(Map map) {
        this.getData().putAll(map);
        return this;
    }

    public Integer getStatus() {
        return status;
    }

    public ResultData setStatus(Integer status) {
        this.status = status;
        return this;
    }

    public boolean isRet() {
        return ret;
    }

    public void setRet(boolean ret) {
        this.ret = ret;
    }

    public String getMessage() {
        return message;
    }

    public ResultData setMessage(String message) {
        this.message = message;
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public ResultData setData(Map<String, Object> data) {
        this.data = data;
        return this;
    }

    public Date getCurrentTime() {
        return currentTime;
    }

    public void setCurrentTime(Date currentTime) {
        this.currentTime = currentTime;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("ResultData{");
        sb.append("ret=").append(ret);
        sb.append(", status=").append(status);
        sb.append(", message='").append(message).append('\'');
        sb.append(", currentTime=").append(currentTime);
        sb.append(", data=").append(data);
        sb.append('}');
        return sb.toString();
    }
}
